<template>
  <div>
    <div v-if="flag">全场清仓，全部5折</div>

    <ul>
      <li v-for="item in goods" :key="item.name">
        <div>{{ item.name }}</div>
        <div>{{ item.price * item.discount }}</div>
        <div>折扣：{{ item.discount * 100 }}%</div>
      </li>
    </ul>
    <input type="text" v-model="newdiscount" />
    <button @click="fn">一点打骨折</button>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      flag: false,
      goods: [
        {
          name: "mac电脑",
          price: "15000",
          discount: 1,
        },
        {
          name: "百事可乐",
          price: "3",
          discount: 1,
        },
        {
          name: "保温杯",
          price: "99",
          discount: 1,
        },
        {
          name: "保暖手套",
          price: "130",
          discount: 1,
        },
      ],
      newdiscount:''
    };
  },
  computed: {

  },

  methods: {
    fn() {
      this.flag = !this.flag;
      console.log(this.newdiscount);
      
      this.goods.forEach((item) => (item.discount = this.newdiscount));
    },
  },
};
</script>

<style scoped>
ul {
  margin: 0;
  padding: 0;
}

li {
  list-style: none;
  width: 200px;
  height: 80px;
  padding: 10px 0 0 0;
  border: 2px solid #333;
}
</style>